<template>
	<view>
		<view class="money column center">
			<text>余额：</text>
			<text>{{ parseFloat(balance).toFixed(2) }}币</text>
		</view>
		
		<view class="recharge">
			<view>充值：</view>
				<view class="list">
					<view :class="{active: index === activeIndex}" 
					v-for="(item, index) in momeyList" :key="index"
					@click="clickItem(index, item)"
					>
						<view>{{item}}币</view>
						
						<view>￥{{item}}</view>
					</view>
				</view>
		</view>
		
		<view class="desc">
			<view>充值说明：</view>
			<view>
				1.在IOS设备的APP要进行充值后，使用虚拟币消费。<br>
				2.充值后不能在非IOS设备使用，与安卓版和网站余额不通用。<br>
				3.充值后没有使用期限，但不可提现、退换、转让和申请发票。<br>
				4.如遇无法充值、充值失败等问题，可关注[梦学谷]公众号，联系我们解决。<br>
			</view>
		</view>
		
		<view class="bottom center">
			<button class="btn" :loading="loading" :disabled="loading" @click="iosPayHandler">立即充值</button>
		</view>
	</view>
</template>

<script>
	import api from '@/api/order.js'
	export default {
		data() {
			return {
				loading:false,
				activeIndex:0,
				couserIds:[] ,//课程Ids
				price:0,//支付金额
				balance:0 ,//我的余额
				applPrice:0,//充值余额
				momeyList:[] //页面渲染金额
			}
		},
		onLoad(option) {
			//接收页面传递过来的参数
			if(option.params){
				const params = JSON.parse(option.params) 
				this.price = params.price
				this.courseIds = params.courseIds
			}
			this.loadData()
		},
		methods: {
			
			clickItem(index,item){
				console.log('index',index);
				this.activeIndex = index
				this.applPrice = item
			},
			
			//充值余额按钮
			iosPayHandler(){
				
			},
			
		
			async loadData(){
				//查询余额
				const {data} = await api.getUserBalance()
				this.balance = data
				
				//计算还差多少金额，则充值多少
				if(this.price){
					// console.log('price',this.price);
					// apple充值余额
					const applPrice = this.balance - this.price
					//先取正数，在往上取整
					this.applPrice =  Math.ceil(Math.abs(applPrice))
				}
				//充值列表
				for(let i = 0;i<6;i++){
					this.momeyList.push(this.applPrice + i*30)
				}
			}
		}
	}
</script>

<style lang="scss">
.money{
	height: 288rpx;
	background-color: $mxg-color-primary;
	color: #FFFFFF;
	font-size: 88rpx;
	text:first-child{
		color: #e7e4e9;
		font-size: 30rpx;
	}
}
.recharge{
	margin: 20rpx 0 0 20rpx;
	font-size: 30rpx;
	color: #999999;
	.list{
		margin-top: 20rpx;
		text-align: center;
		>view{
			float: left;
			width: 225rpx;
			border: 1px solid $mxg-color-grey;
			border-radius: 10rpx;
			background-color: #FFFFFF;
			margin-right: 10rpx;
			margin-bottom: 15rpx;
			padding: 20rpx 0;
			flex-wrap: wrap;
			view:first-child {
				color: $mxg-text-color-red;
				font-size: 36rpx;
			}
		}
	}
}

.active{
	box-shadow: 0 0 0 0.5px $mxg-text-color-red;
}
.desc{
	// 清除浮动
	clear: both;
	margin: 0 20rpx;
	font-size: 30rpx;
	line-height: 45rpx;
	color: #6e6d70;
	view:first-child {
		font-weight: bold;
		padding-top: 50rpx;
		padding-bottom: 30rpx;
	}
	view:last-child {
		padding-bottom: 120rpx;
	}
	
}
.bottom{
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	height: 100rpx;
	background-color: #FFFFFF;
	border-top: $mxg-underline;
	font-size: 35rpx;
	.btn {
		width: 700rpx;
		background-color: $mxg-color-primary;
		color: #FFFFFF;
		border-radius: 50rpx;
		line-height: 80rpx;
		font-size: 30rpx;
		&::after {
			// 加载中隐藏边框
			border: none;
		}
	}
}
</style>
